Mail::SpamAssassin::Conf - SpamAssassin configuration file
# a comment
rewrite_subject 1
full PARA_A_2_C_OF_1618 /Paragraph .a.{0,10}2.{0,10}C. of S. 1618/i describe PARA_A_2_C_OF_1618 Claims compliance with senate bill 1618
header FROM_HAS_MIXED_NUMS From =~ /\d+[a-z]+\d+\S*@/i describe FROM_HAS_MIXED_NUMS From: contains numbers mixed in with letters
score A_HREF_TO_REMOVE 2.0
lang es describe FROM_FORGED_HOTMAIL Forzado From: simula ser de hotmail.com
SpamAssassin is configured using some traditional UNIX-style configuration files, loaded from the /usr/share/spamassassin and /etc/mail/spamassassin directories.
The #
character starts a comment, which continues until end of line.
Whitespace in the files is not significant, but please note that starting a line with whitespace is deprecated, as we reserve its use for multi-line rule definitions, at some point in the future.
Paths can use ~
to refer to the user's home directory.
Where appropriate, default values are listed in parentheses.
e.g.
version_tag myrules1 # version=2.41-myrules1
Whitelist and blacklist addresses are now file-glob-style patterns, so
friend@somewhere.com
, *@isp.com
, or *.domain.net
will all work.
Specifically, *
and ?
are allowed, but all other metacharacters are not.
Regular expressions are not used for security reasons.
Multiple addresses per line, separated by spaces, is OK. Multiple
whitelist_from
lines is also OK.
The headers checked for whitelist addresses are as follows: if Resent-From
is set, use that; otherwise check all addresses taken from the following
set of headers:
Envelope-Sender Resent-Sender X-Envelope-From From
e.g.
whitelist_from joe@example.com fred@example.com whitelist_from *@example.com
user_prefs
file.
The specified email address has to match exactly the address previously
used in a whitelist_from line.
e.g.
unwhitelist_from joe@example.com fred@example.com unwhitelist_from *@example.com
e.g.
whitelist_from_rcvd joe@example.com example.com whitelist_from_rcvd *@axkit.org sergeant.org
user_prefs
file.
The specified email address has to match exactly the address previously
used in a whitelist_from_rcvd line.
e.g.
unwhitelist_from_rcvd joe@example.com fred@example.com unwhitelist_from_rcvd *@axkit.org
whitelist_from
.
user_prefs
file.
e.g.
unblacklist_from joe@example.com fred@example.com unblacklist_from *@spammer.com
To:
or Cc:
headers, mail will be
whitelisted. Useful if you're deploying SpamAssassin system-wide, and don't
want some users to have their mail filtered. Same format as whitelist_from
.
There are three levels of To-whitelisting, whitelist_to
, more_spam_to
and all_spam_to
. Users in the first level may still get some spammish
mails blocked, but users in all_spam_to
should never get mail blocked.
n.nn
can
be an integer or a real number. 5.0 is the default setting, and is quite
aggressive; it would be suitable for a single-user setup, but if you're an ISP
installing SpamAssassin, you should probably set the default to be more
conservative, like 8.0 or 10.0. It is not recommended to automatically delete
or discard messages marked as spam, as your users will complain, but if you
choose to do so, only delete messages with an exceptionally high score such as
15.0 or higher.
SYMBOLIC_TEST_NAME
is
the symbolic name used by SpamAssassin for that test; for example,
'FROM_ENDS_IN_NUMS'.
If only one valid score is listed, then that score is always used for a test.
If four valid scores are listed, then the score that is used depends on how SpamAssassin is being used. The first score is used when both Bayes and network tests are disabled. The second score is used when Bayes is disabled, but network tests are enabled. The third score is used when Bayes is enabled and network tests are disabled. The fourth score is used when Bayes is enabled and network tests are enabled.
Setting a rule's score to 0 will disable that rule from running.
Note that test names which begin with '__' are reserved for meta-match sub-rules, and are not scored or listed in the 'tests hit' reports.
If no score is given for a test, the default score is 1.0, or 0.01 for tests whose names begin with 'T_' (this is used to indicate a rule under test).
1
, the report will
be included in the X-Spam-Report header, even if the message is not tagged
as spam. Note that the report text always states that the mail is spam,
since normally the report is only added if the mail is spam.
This can be useful if you want to know what rules the mail triggered, and why it was not tagged as spam. See also always_add_headers.
X-Spam-Level: *******
This can be useful for MUA rule creation.
In other words, for a message scoring 7.2 points with this option set to .
X-Spam-Level: .......
Subject:
line of mails that are considered spam,
if rewrite_subject
is 1. _HITS_ in the tag will be replace with the calculated
score for this message. _REQD_ will be replaced with the threshold.
If this option is set to 2, then original messages will be attached with a content type of text/plain instead of message/rfc822. This setting may be required for safety reasons on certain broken mail clients that automatically load attachments without any action by the user. This setting may also make it somewhat more difficult to extract or view the original message.
If this option is set to 0, incoming spam is only modified by adding some headers and no changes will be made to the body.
1
.
Note that the language cannot always be recognized reliably. In that case, no points will be assigned.
The rule UNDESIRED_LANGUAGE_BODY
is triggered based on how this is set.
The following languages are recognized. In your configuration, you must use
the language specifier located in the first column, not the English name for
the language. You may also specify all
if your language is not listed, or
if you want to allow any language. The default setting is all
.
examples:
ok_languages all (allow all languages) ok_languages en (only allow English) ok_languages en ja zh (allow English, Japanese, and Chinese)
Note: if there are multiple ok_languages lines, only the last one is used.
If you receive lots of spam in foreign languages, and never get any non-spam in these languages, this may help. Note that all ISO-8859-* character sets, and Windows code page character sets, are always permitted by default.
Set this to all
to allow all character sets. This is the default.
The rules CHARSET_FARAWAY
, CHARSET_FARAWAY_BODY
, and
CHARSET_FARAWAY_HEADERS
are triggered based on how this is set.
Select the locales to allow from the list below:
examples:
ok_locales all (allow all locales) ok_locales en (only allow English) ok_locales en ja zh (allow English, Japanese, and Chinese)
Note: if there are multiple ok_locales lines, only the last one is used.
Note that test names which begin with '__' are reserved for meta-match sub-rules, and are not scored or listed in the 'tests hit' reports.
10_misc.cf
configuration file in /usr/share/spamassassin
for an
example.
If you change this, try to keep it under 76 columns (inside the the dots
below). Bear in mind that EVERY line will be prefixed with ``SPAM: '' in order
to make it clear what's been added, and allow other filters to remove
spamfilter modifications, so you lose 6 columns right there. Also note that the
first line of the report must start with 4 dashes, for the same reason. Each
report
line appends to the existing template, so use
clear_report_template
to restart.
The following template items are supported, and will be filled out by SpamAssassin:
10_misc.cf
configuration file in
/usr/share/spamassassin
for an example.
Each unsafe-report
line appends to the existing template, so use
clear_unsafe_report_template
to restart.
10_misc.cf
configuration file in
/usr/share/spamassassin
for an example.
Xxxxxx: yyy
where Xxxxxx is a header and yyy is some text, they'll be used
as headers. See the 10_misc.cf
configuration file in
/usr/share/spamassassin
for an example.
As nearly all DCC clients are auto-reporting these checksums you should set this to a relatively high value, e.g. 999999 (this is DCC's MANY count).
The default is 999999 for all these options.
The default is to not add the header.
The default is 5.
The default is to not add the header.
You can however specify your own list by specifying
dns_available test: server1.tld server2.tld server3.tld
Please note, the DNS test queries for MX records so if you specify your
own list of servers, please make sure to choose the one(s)
which has an
associated MX record.
mean
), and then once we have otherwise fully calculated the
score for this message (score
), we calculate the final score for the
message as:
finalscore
= score
+ (mean
- score
) * factor
So if factor
= 0.5, then we'll move to half way between the calculated
score and the mean. If factor
= 0.3, then we'll move about 1/3 of the way
from the score toward the mean. factor
= 1 means just use the long-term
mean; factor
= 0 mean just use the calculated score.
Note that certain tests are ignored when determining whether a message should be trained upon: - auto-whitelist (AWL) - rules with tflags set to 'learn' (the Bayesian rules) - rules with tflags set to 'userconf' (user white/black-listing rules, etc)
Also note that auto-training occurs using scores from either scoreset 0 or 1, depending on what scoreset is used during message check. It is likely that the message check and auto-train scores will be different.
bayes_ignore_header X-Upstream-Spamfilter bayes_ignore_header X-Upstream-SomethingElse
These settings differ from the ones above, in that they are considered
'privileged'. Only users running spamassassin
from their procmailrc's or
forward files, or sysadmins editing a file in /etc/mail/spamassassin
, can
use them. spamd
users cannot use them in their user_prefs
files, for
security and efficiency reasons, unless allow_user_rules is enabled (and
then, they may only add rules from below).
user_prefs
files for use with spamd
. It defaults to off, because
this could be a severe security hole. It may be possible for users to
gain root level access if spamd
is run as root. It is NOT a good
idea, unless you have some other way of ensuring that users' tests are
safe. Don't use this unless you are certain you know what you are
doing. Furthermore, this option causes spamassassin to recompile all
the tests each time it processes a message for a user with a rule in
his/her user_prefs
file, which could have a significant effect on
server load. It is not recommended.
SYMBOLIC_TEST_NAME
is a symbolic test name, such as
'FROM_ENDS_IN_NUMS'. header
is the name of a mail header, such as
'Subject', 'To', etc.
'ALL' can be used to mean the text of all the message's headers. 'ToCc' can be used to mean the contents of both the 'To' and 'Cc' headers.
'MESSAGEID' is a symbol meaning all Message-Id's found in the message; some mailing list software moves the real Message-Id to 'Resent-Message-Id' or 'X-Message-Id', then uses its own one in the 'Message-Id' header. The value returned for this symbol is the text from all 3 headers, separated by newlines.
op
is either =~
(contains regular expression) or !~
(does not contain
regular expression), and pattern
is a valid Perl regular expression, with
modifiers
as regexp modifiers in the usual style.
If the [if-unset: STRING]
tag is present, then STRING
will
be used if the header is not found in the mail message.
Test names should not start with a number, and must contain only alphanumerics and underscores. It is suggested that lower-case characters not be used, as an informal convention. Dashes are not allowed.
Note that test names which begin with '__' are reserved for meta-match sub-rules, and are not scored or listed in the 'tests hit' reports. Test names which begin with 'T_' are reserved for tests which are undergoing QA, and these are given a very low score.
If you add or modify a test, please be sure to run a sanity check afterwards
by running spamassassin --lint
. This will avoid confusing error
messages, or other tests being skipped as a side-effect.
name_of_header
is the name of a
header to test for existence. This is just a very simple version of
the above header tests.
name_of_eval_method
is the name of
a method on the Mail::SpamAssassin::EvalTests
object. arguments
are optional arguments to the function call.
pattern
is a Perl regular expression.
The 'body' in this case is the textual parts of the message body; any non-text MIME parts are stripped, and the message decoded from Quoted-Printable or Base-64-encoded format if necessary. All HTML tags and line breaks will be removed before matching.
pattern
is a Perl regular expression.
The 'uri' in this case is a list of all the URIs in the body of the email, and the test will be run on each and every one of those URIs, adjusting the score if a match is found. Use this test instead of one of the body tests when you need to match a URI, as it is more accurately bound to the start/end points of the URI, and will also be faster.
pattern
is a Perl regular expression.
The 'raw body' of a message is the text, including all textual parts. The text will be decoded from base64 or quoted-printable encoding, but HTML tags and line breaks will still be present.
pattern
is a Perl regular expression.
The 'full body' of a message is the un-decoded text, including all parts
(including images or other attachments). SpamAssassin no longer tests
full tests against decoded text; use rawbody
for that.
meta META1 TEST1 && !(TEST2 || TEST3)
Note that English language operators (``and'', ``or'') will be treated as
rule names, and that there is no XOR
operator.
meta META2 (3 * TEST1 - 2 * TEST2) > 0
Note that Perl builtins and functions, like abs()
, can't be
used, and will be treated as rule names.
If you want to define a meta-rule, but do not want its individual sub-rules to count towards the final score unless the entire meta-rule matches, give the sub-rules names that start with '__' (two underscores). SpamAssassin will ignore these for scoring.
These settings differ from the ones above, in that they are considered 'more
privileged' -- even more than the ones in the SETTINGS section. No matter what
allow_user_rules
is set to, these can never be set from a user's
user_prefs
file.
These tests are only run as part of the test suite - they should not affect the general running of SpamAssassin.
pyzor
client
instead of relying on SpamAssassin to find it in the current PATH.
Note that if taint mode is enabled in the Perl interpreter, you should
use this, as the current PATH will have been cleared.
dccproc
client instead of relying on SpamAssassin to find it in the current PATH.
Note that if taint mode is enabled in the Perl interpreter, you should
use this, as the current PATH will have been cleared.
dccproc(8)
command. Please note that only
[A-Z -] is allowed (security).
The default is -R
~/.spamassassin
directory with mode 0700, but for system-wide
SpamAssassin use, you may want to share this across all users.
_toks
, _seen
etc. appended to this filename;
so the default setting results in files called ~/.spamassassin/bayes_seen
,
~/.spamassassin/bayes_toks
etc.
By default, each user has their own, in their ~/.spamassassin
directory with
mode 0700/0600, but for system-wide SpamAssassin use, you may want to reduce
disk space usage by sharing this across all users. (However it should be noted
that Bayesian filtering appears to be more effective with an individual
database per user.)
unixdate_messageid
(i.e 1023257504_chuvn31gdu@4ax.com)
Make sure SA can write the log file; if you're not sure what permissions are needed, chmod the log directory to 1777, and adjust later.
Make sure you specify this using the 'x' mode bits set, as it may also be used to create directories. However, if a file is created, the resulting file will not have any execute bits set (the umask is set to 111).
Make sure you specify this using the 'x' mode bits set, as it may also be used to create directories. However, if a file is created, the resulting file will not have any execute bits set (the umask is set to 111).
bayes_expiry_min_db_size
size).
DBI:mysql:spamassassin:localhost
username
.
preference
.
value
.
spamassassin
.
WARNING!!! When passing a reference to a hash, you need to put the whole hash
in one line for the parser to read it correctly (you can check with
spamassassin -D < mesg
).
Set this to what your RBLs return for dialup IPs It is used by dialup-firsthop and relay-firsthop rules so that you can match DUL codes and compensate DUL checks with a negative score if the IP is a dialup IP the mail originated from and it was properly relayed by a hop before reaching you (hopefully not your secondary MX :-) The trailing ``-firsthop'' is magic, it's what triggers the RBL to only be run on the originating hop The idea is to not penalize (or penalize less) people who properly relayed through their ISP's mail server
Here's an example showing the use of Osirusoft and MAPS DUL, as well as the use of check_two_rbl_results to compensate for a match in both RBLs:
header RCVD_IN_DUL rbleval:check_rbl('dialup', 'dialups.mail-abuse.org.') describe RCVD_IN_DUL Received from dialup, see http://www.mail-abuse.org/dul/ score RCVD_IN_DUL 4
header X_RCVD_IN_DUL_FH rbleval:check_rbl('dialup-firsthop', 'dialups.mail-abuse.org.') describe X_RCVD_IN_DUL_FH Received from first hop dialup, see http://www.mail-abuse.org/dul/ score X_RCVD_IN_DUL_FH -3
header RCVD_IN_OSIRUSOFT_COM rbleval:check_rbl('osirusoft', 'relays.osirusoft.com.') describe RCVD_IN_OSIRUSOFT_COM Received via an IP flagged in relays.osirusoft.com
header X_OSIRU_SPAM_SRC rbleval:check_rbl_results_for('osirusoft', '127.0.0.4') describe X_OSIRU_SPAM_SRC DNSBL: sender is Confirmed Spam Source, penalizing further score X_OSIRU_SPAM_SRC 3.0
header X_OSIRU_SPAMWARE_SITE rbleval:check_rbl_results_for('osirusoft', '127.0.0.6') describe X_OSIRU_SPAMWARE_SITE DNSBL: sender is a Spamware site or vendor, penalizing further score X_OSIRU_SPAMWARE_SITE 5.0
header X_OSIRU_DUL_FH rbleval:check_rbl('osirusoft-dul-firsthop', 'relays.osirusoft.com.') describe X_OSIRU_DUL_FH Received from first hop dialup listed in relays.osirusoft.com score X_OSIRU_DUL_FH -1.5
header Z_FUDGE_DUL_MAPS_OSIRU rblreseval:check_two_rbl_results('osirusoft', "127.0.0.3", 'dialup', "127.0.0.3") describe Z_FUDGE_DUL_MAPS_OSIRU Do not double penalize for MAPS DUL and Osirusoft DUL score Z_FUDGE_DUL_MAPS_OSIRU -2
header Z_FUDGE_RELAY_OSIRU rblreseval:check_two_rbl_results('osirusoft', "127.0.0.2", 'relay', "127.0.0.2") describe Z_FUDGE_RELAY_OSIRU Do not double penalize for being an open relay on Osirusoft and another DNSBL score Z_FUDGE_RELAY_OSIRU -2
header Z_FUDGE_DUL_OSIRU_FH rblreseval:check_two_rbl_results('osirusoft-dul-firsthop', "127.0.0.3", 'dialup-firsthop', "127.0.0.3") describe Z_FUDGE_DUL_OSIRU_FH Do not double compensate for MAPS DUL and Osirusoft DUL first hop dialup score Z_FUDGE_DUL_OSIRU_FH 1.5
=cut
if (/^dialup_codes\s+(.*)$/) { $self->{dialup_codes} = eval $1; next; }
###########################################################################
failed_line: my $msg = ``Failed to parse line in SpamAssassin configuration, ''. ``skipping: $_'';
if ($self->{lint_rules}) { warn $msg."\n"; } else { dbg ($msg); } $self->{errors}++; } }
sub add_test { my ($self, $name, $text, $type) = @_; $self->{tests}->{$name} = $text; $self->{test_types}->{$name} = $type; $self->{tflags}->{$name} ||= ''; $self->{source_file}->{$name} = $self->{currentfile};
# All scoresets should have a score defined, so if the one we're in doesn't, we need to set them all. if ( ! exists $self->{scores}->{$name} ) { # T_ rules (in a testing probationary period) get low, low scores my $set_score = $name=~/^T_/ ? 0.01 : 1.0; for my $index (0..3) { $self->{scoreset}->[$index]->{$name} = $set_score; } } }
sub add_regression_test { my ($self, $name, $ok_or_fail, $string) = @_; if ($self->{regression_tests}->{$name}) { push @{$self->{regression_tests}->{$name}}, [$ok_or_fail, $string]; } else { # initialize the array, and create one element $self->{regression_tests}->{$name} = [ [$ok_or_fail, $string] ]; } }
sub regression_tests { my $self = shift; if (@_ == 1) { # we specified a symbolic name, return the strings my $name = shift; my $tests = $self->{regression_tests}->{$name}; return @$tests; } else { # no name asked for, just return the symbolic names we have tests for return keys %{$self->{regression_tests}}; } }
# note: error 70 == SA_SOFTWARE sub finish_parsing { my ($self) = @_;
while (my ($name, $text) = each %{$self->{tests}}) { my $type = $self->{test_types}->{$name};
# eval type handling if (($type & 1) == 1) { my @args; if (my ($function, $args) = ($text =~ m/(.*?)\s*\((.*?)\)\s*$/)) { if ($args) { @args = ($args =~ m/['"](.*?)['"]\s*(?:,\s*|$)/g); } unshift(@args, $function); if ($type == TYPE_BODY_EVALS) { $self->{body_evals}->{$name} = \@args; } elsif ($type == TYPE_HEAD_EVALS) { $self->{head_evals}->{$name} = \@args; } elsif ($type == TYPE_RBL_EVALS) { $self->{rbl_evals}->{$name} = \@args; } elsif ($type == TYPE_RBL_RES_EVALS) { $self->{rbl_res_evals}->{$name} = \@args; } elsif ($type == TYPE_RAWBODY_EVALS) { $self->{rawbody_evals}->{$name} = \@args; } elsif ($type == TYPE_FULL_EVALS) { $self->{full_evals}->{$name} = \@args; } #elsif ($type == TYPE_URI_EVALS) { # $self->{uri_evals}->{$name} = \@args; #} else { $self->{errors}++; sa_die(70, "unknown type $type for $name: $text"); } } else { $self->{errors}++; sa_die(70, "syntax error for $name: $text"); } } # non-eval tests else { if ($type == TYPE_BODY_TESTS) { $self->{body_tests}->{$name} = $text; } elsif ($type == TYPE_HEAD_TESTS) { $self->{head_tests}->{$name} = $text; } elsif ($type == TYPE_META_TESTS) { $self->{meta_tests}->{$name} = $text; } elsif ($type == TYPE_URI_TESTS) { $self->{uri_tests}->{$name} = $text; } elsif ($type == TYPE_RAWBODY_TESTS) { $self->{rawbody_tests}->{$name} = $text; } elsif ($type == TYPE_FULL_TESTS) { $self->{full_tests}->{$name} = $text; } else { $self->{errors}++; sa_die(70, "unknown type $type for $name: $text"); } } }
delete $self->{tests}; # free it up }
sub add_to_addrlist { my ($self, $singlelist, @addrs) = @_;
foreach my $addr (@addrs) { my $re = lc $addr; $re =~ s/[\000\\\(]/_/gs; # paranoia $re =~ s/([^\*\?_a-zA-Z0-9])/\\$1/g; # escape any possible metachars $re =~ tr/?/./; # "?" -> "." $re =~ s/\*/\.\*/g; # "*" -> "any string" $self->{$singlelist}->{$addr} = qr/^${re}$/; } }
sub add_to_addrlist_rcvd { my ($self, $listname, $addr, $domain) = @_;
my $re = lc $addr; $re =~ s/[\000\\\(]/_/gs; # paranoia $re =~ s/([^\*\?_a-zA-Z0-9])/\\$1/g; # escape any possible metachars $re =~ tr/?/./; # "?" -> "." $re =~ s/\*/\.\*/g; # "*" -> "any string" $self->{$listname}->{$addr}{re} = qr/^${re}$/; $self->{$listname}->{$addr}{domain} = $domain; }
sub remove_from_addrlist { my ($self, $singlelist, @addrs) = @_;
foreach my $addr (@addrs) { delete($self->{$singlelist}->{$addr}); } }
sub remove_from_addrlist_rcvd { my ($self, $listname, @addrs) = @_; foreach my $addr (@addrs) { delete($self->{$listname}->{$addr}); } }
###########################################################################
sub maybe_header_only {
my($self,$rulename)
= @_;
my $type = $self->{test_types}->{$rulename};
return 0 if (!defined ($type));
if (($type == TYPE_HEAD_TESTS) || ($type == TYPE_HEAD_EVALS)) { return 1;
} elsif ($type == TYPE_META_TESTS) { my $tflags = $self->{tflags}->{$rulename}; $tflags ||= ''; if ($tflags =~ m/\bnet\b/i) { return 0; } else { return 1; } }
return 0; }
sub maybe_body_only {
my($self,$rulename)
= @_;
my $type = $self->{test_types}->{$rulename};
return 0 if (!defined ($type));
if (($type == TYPE_BODY_TESTS) || ($type == TYPE_BODY_EVALS) || ($type == TYPE_URI_TESTS) || ($type == TYPE_URI_EVALS)) { # some rawbody go off of headers... return 1;
} elsif ($type == TYPE_META_TESTS) { my $tflags = $self->{tflags}->{$rulename}; $tflags ||= ''; if ($tflags =~ m/\bnet\b/i) { return 0; } else { return 1; } }
return 0; }
###########################################################################
sub dbg { Mail::SpamAssassin::dbg (@_); } sub sa_die { Mail::SpamAssassin::sa_die (@_); }
###########################################################################
1; __END__
A line starting with the text lang xx
will only be interpreted
if the user is in that locale, allowing test descriptions and
templates to be set for that language.
Mail::SpamAssassin
spamassassin
spamd